<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link rel="icon" href="${una}/ub-admin/img/favicon.png" type="image/x-icon">
    <link rel="shortcut icon" href="${una}/ub-admin/img/favicon.png" type="image/x-icon">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="x-ua-compatible" content="ie=edge">

    <title>新建任务 - UnaBoot</title>
    <link rel="stylesheet" href="${una}/ub-admin/plugin/fontawesome-free/css/all.min.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/font-awesome.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/ionicons.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/adminlte.min.css">
    <link rel="stylesheet" href="${una}/ub-admin/plugin/layer/skin/default/layer.css"/>
    <link rel="stylesheet" href="${una}/ub-admin/css/unaboot-admin.css">
    <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
    <style>
    </style>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-12 pt-2">
            <form id="schedule-form">
                <div class="form-group row">
                    <label class="col-3 col-form-label font-weight-normal text-right" for="method">计划类型<small class="text-danger">(*必填)</small></label>
                    <div class="col-8">
                        <select type="text" class="form-control" name="method" id="method" >
                            <#if methods?? && methods?size gt 0>
                                <#list methods as method>
                                    <#if method.getName() != "publishPost">
                                        <option value="${method.getName()}">${method.getAlias()}</option>
                                    </#if>
                                </#list>
                            </#if>
                        </select>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-3 col-form-label font-weight-normal text-right" for="cronExp">Cron表达式<small class="text-danger">(*必填)</small></label>
                    <div class="col-8">
                        <input type="text" class="form-control" name="cronExp" id="cronExp" placeholder="请输入cron表达式">
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-3 col-form-label font-weight-normal text-right" for="state">是否立即生效</label>
                    <div class="col-8">
                        <div class="custom-control custom-radio custom-control-inline pr-4">
                            <input type="radio" id="enabled-on" name="state" value="1" checked class="custom-control-input">
                            <label class="custom-control-label font-weight-normal" for="enabled-on">是(Y)</label>
                        </div>
                        <div class="custom-control custom-radio custom-control-inline">
                            <input type="radio" id="enabled-off" name="state" value="0" class="custom-control-input">
                            <label class="custom-control-label font-weight-normal" for="enabled-off">否(N)</label>
                        </div>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-3 col-form-label font-weight-normal text-right" for="introduce">计划简介<small class="text-danger">(*必填)</small></label>
                    <div class="col-8">
                        <textarea class="form-control" rows="2" name="introduce" id="introduce"></textarea>
                    </div>
                </div>
                <div class="fixed-bottom pl-4 pt-2 pr-4 pb-2 bg-gray-light text-right">
                    <button type="button" class="btn btn-sm btn-primary" id="save-data"><i class="fa fa-save"></i> 保存</button>
                    <button type="button" class="btn btn-sm btn-default" id="close"><i class="fa fa-times-circle-o"></i> 取消</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="${una}/ub-admin/plugin/jquery/jquery.min.js"></script>
<script src="${una}/ub-admin/plugin/jquery/jquery.serialize.js"></script>
<script src="${una}/ub-admin/plugin/jquery/jquery.form.js"></script>
<script src="${una}/ub-admin/plugin/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="${una}/ub-admin/js/adminlte.js"></script>
<script type="text/javascript" src="${una}/ub-admin/plugin/layer/layer.js"></script>
<script src="${una}/ub-admin/js/jquery.validate.min.js"></script>
<script type="text/javascript">
    var form = $("#schedule-form");
    form.validate({
        errorPlacement: function errorPlacement(error, element) {
            element.after(error);
        },
        rules:{
            method:{
                required:true
            },
            introduce:{
                required:true
            },
            cronExp:{
                required:true
            }
        },
        messages:{
            method:{
                required:'请选择计划类型'
            },
            introduce: {
                required:'请填写计划介绍信息'
            },
            cronExp:{
                required:'cron表达式必须填写'
            }
        }
    });
    $("#save-data").on("click",function(){
        var flag =  form.valid();
        if(flag){
            var data = $("#schedule-form").serialize();
            var load = layer.load(2,{shade:[0.4,'#f0f0f0f0']});
            $.ajax({
                type:'POST',
                url:"${una}/admin/schedules/create",
                data:data,
                success:function(){
                    var index = parent.layer.getFrameIndex(window.name);
                    layer.alert("当前操作已成功执行!", {
                        title: "<i class='fa fa-info'></i> 提示",
                        icon: 1,
                        shade: [0.4, "#fff"],
                        shadeClose: false,
                        time: 0,
                        btn: ['OK'],
                        yes: function (newIndex) {
                            parent.layer.close(index);
                            parent.layer.close(newIndex);
                            parent.location.reload();
                        }
                    });
                },
                error:function(){
                    layer.close(load);
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.alert("当前操作失败!请稍后再试。",{
                        title:"<i class='fa fa-info'></i> 提示",
                        icon:1,
                        shade:[0.4,"#fff"],
                        shadeClose:false,
                        time:0,
                        btn:['OK'],
                        yes:function(newIndex){
                            parent.layer.close(index);
                            parent.layer.close(newIndex);
                        }
                    });
                }
            });
        }
    });
    $("#close").on("click",function(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    });
</script>
</body>
</html>
